<template>
  <div class="fileData">
    <van-tabs v-model="active" color="#007DFB" line-width="60px" line-height="4px" title-active-color="#007DFB">
      <van-tab title="选图集选工匠" v-if="!isnew">
        <ChooseCraftsman v-if="!isnew" @handleactive="handleactive" :SGXKData="rowData" />
        <selectCompany v-else />
      </van-tab>
      <van-tab title="签合同" v-if="!isnew">
        <ConstructionContract @handleactive2="handleactive" :SGXKData="rowData" />
      </van-tab>
      <!-- <van-tab title="申请表单">
        <xiangqing @handleactive1="handleactive" :rowGuid="rowData" :GJData="GJData" />
      </van-tab> -->
      <van-tab title="承诺书">
        <chengNS />
      </van-tab>
    </van-tabs>
  </div>
</template>

<style lang="scss" scoped>
.fileData {
  padding: 10px;
  font-size: 14px;
  height: 100vh;
  color: black;

  .huadong {
    height: 84vh;
    overflow: auto;
  }

  .top {
    font-weight: 548;

    h3 {
      line-height: 36px;
    }

    .p {
      line-height: 24px;
      height: 70px;
    }
  }

  .middle {
    h3 {
      line-height: 36px;
    }

    .p {
      line-height: 24px;
      height: 30px;
    }
  }

  .footer {
    position: fixed;
    bottom: 10px;
    right: 50%;
    transform: translateX(50%);
  }
}
</style>

<script>
import upLoad from '@/utils/upLoad'
import xiangqing from './xiangqing.vue'
import ChooseCraftsman from '../ChooseCraftsman.vue'
import { GJDBFunction2 } from '@/utils/queryData'
import chengNS from './chengNS.vue'
import ConstructionContract from '../ConstructionContract.vue'
import { QuerySignCallback,FileServerProxy } from '../../../utils/api'
import selectCompany from '../../newZlb/selectCompany.vue'
export default {
  watch: {
    $route: {
      handler: function (val, oldVal) {
        console.log(val, 'handler')
      },
      // 深度观察监听
      deep: true
    }
  },
  data() {
    return {
      active: 0,
      rowData: {},
      GJData: {},
      isnew:false,
      FJData1: [
        {
          title: '',
          groupGuid: '依法办理用地批准手续的证明文件',
          FileName: '无',
          fileList: []
        }
      ],
      FJData2: [
        {
          title: '',
          groupGuid: '施工图设计文件审查合格书',
          FileName: '无',
          fileList: []
        }
      ],
      FJData3: [
        {
          title: '',
          groupGuid: '现场照片',
          FileName: '无',
          fileList: []
        }
      ],
      FJData4: [
        {
          title: '',
          groupGuid: 'e44e3da4-dc5a-434e-b682-033bf47ff1f4',
          FileName: '无',
          fileList: []
        }
      ],
      FJData5: [
        {
          title: '',
          groupGuid: '2774cbb5-1854-4a0a-afaf-bee2e8f83cab',
          FileName: '无',
          fileList: []
        }
      ],
      FJData6: [
        {
          title: '',
          groupGuid: '618bd7e6-cd39-46c2-b0f7-56eef4bbb456',
          FileName: '无',
          fileList: []
        }
      ]
    }
  },
  created() {
    this.isnew = this.$store.state.VERSIONNUMBER == 1 ? true : false
    // window.addEventListener('setItem', () => {

    // })
    // if (window.sessionStorage.getItem('active')) {
    //     this.active = Number(window.sessionStorage.getItem('active'))
    //     console.log(this.active, 'this.active')
    //     // this.GJData = JSON.parse(window.sessionStorage.getItem('GJdata'))
    // }
    this.rowData = JSON.parse(window.sessionStorage.getItem('fileData'))
    console.log(this.rowData)
    this.getHuanjie()
    window.localStorage.setItem('GJRowGUID', this.rowData.ROW_GUID)
    this.getData()
  },
  beforeDestroy() {
    // 移除对 sessionStorage 的监听
    window.removeEventListener('setItem', () => {})
  },
  mounted() {},
  methods: {
    //获取施工备案类型
    /**
           * 	'1' -- 施工备案证申请
              '2' -- 施工备案证变更
              '3' -- 施工备案证中止
              '4' -- 施工备案证恢复
              '5' -- 施工备案证延期
           */
    handleactive(data) {
      debugger
      //更新状态
      let rowGuid1 = JSON.parse(window.sessionStorage.getItem('fileData'))
      if(rowGuid1.OLD_GJ ==0){
        this.changeoled(1)
      }
      //重新获取当前行数据
      this.getDangqianhangData()
      this.active = data
    },
    handleactive1() {
      this.active = 4
    },
    async getDangqianhangData() {
      let isNHApplyParamNH = {
        procName: 'ZJBXDBX',
        dtParams: JSON.stringify([{ I_USERID: "'" + this.rowData.ROW_GUID + "'", I_SJH: "'" + window.localStorage.getItem('serialNumber') + "'" }]),
        token: window.localStorage.getItem('token')
      }
      let xcfycjtfnApplynh = {
        accessCode: '69db6bece3a7480592e2ec753d1e335e',
        cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
        params: isNHApplyParamNH
      }
      const resxcfycjtApplynh = await FileServerProxy(xcfycjtfnApplynh)
      let data = JSON.parse(resxcfycjtApplynh.data.data).Data[0]
      window.sessionStorage.setItem('fileData', JSON.stringify(data))
    },
    async changeoled(data) {
      const res = await GJDBFunction2('up_sgxkjd', [{ I_ROW_GUID: this.rowData.ROW_GUID, I_TYPE: 1 }])
    },
    async getData() {
      const res = await GJDBFunction2('get_SGXK_TYPE', [{ task_recipient: this.rowData.ROW_GUID }])
      //将返回值存入localhost
      window.sessionStorage.setItem('RUNTYPE', res[0].RUNTYPE)
    },
    //查询当前环节
    async getHuanjie() {
      let params = {
        dataguid: '6b96a8d0-7e3e-4dd7-bcd0-191f000fce32',
        searchObject: JSON.stringify([{ field: 'entityrowguid', value: this.rowData.ROW_GUID }]),
        token: window.localStorage.getItem('token')
      }
      let params1 = {
        accessCode: '688bd3883572440a859dfd8ba9194e7b',
        cityCode: window.localStorage.getItem('citycodeChange') ? window.localStorage.getItem('citycodeChange') : '441300000000',
        params: params
      }
      const res = await QuerySignCallback(params1)
      const result = JSON.parse(res.data.data).Data
      console.log(result, 'dvndnsz')
      //根据返回的TJBH是否有值可以判断是否到签合同
      if (!result[0]?.TJBH) {
        this.active = 0
      } else if (!result[0].HTBHQDZT || !result[0].F_JZQYXMFZR || !result[0].F_JZQYSGFZR) {
        this.active = 1
        // this.changeoled(1)
      }
    }
  },
  components: {
    xiangqing,
    upLoad,
    chengNS,
    ChooseCraftsman,
    ConstructionContract,
    selectCompany
  }
}
</script>
